package com.company;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/*用例
5
3
5
1
8
4
 */
public class 小Q爬塔 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        //输入塔高n<=10000
        int n = scanner.nextInt();
        //存放每层高度
        List<Integer> list = new ArrayList<Integer>();
        for (int i = 0; i < n; i++)
            list.add(scanner.nextInt());
        //定义到这层是爬还是跳
        int[] pa = new int[10000];
        int[] tiao = new int[10000];
        pa[0] = 0;
        pa[1] = list.get(0);
        tiao[0] = 0;
        tiao[1] = 0;
        for (int i = 2; i <= n; i++){
            pa[i] = Math.min(pa[i-1], tiao[i-1]) + list.get(i-1);
            tiao[i] = Math.min(pa[i-1], i-2>=0?pa[i-2]:pa[i-1]);
            //System.out.println("第"+i+"层 pa["+i+"] is "+pa[i]+", tiao["+i+"] is "+tiao[i]);
        }
        System.out.println(Math.min(pa[n], tiao[n]));
    }
}
